provinceList();
function provinceList(){
    $.ajax({
        cache : true,
        type : "get",
        url:'/js/city.json',
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            let str = '';
            data.forEach(function (val,k){
                if( k == 0 ){
                    str += `<option value="">请选择</option>`
                }
                str += `<option value="${val.name}">${val.name}</option>`
            })
            $("#province").html(str);
        }
    });

    if( $("#province1").val() ){

        $("#province").val($("#province1").val())

        $("#province").find('option').each(function (k,v){
            if( $("#province1").val() == $(v).val() ){

                $.ajax({
                    cache : true,
                    type : "get",
                    url:'/js/city.json',
                    async : false,
                    error : function(request) {
                        parent.layer.alert("Connection error");
                    },
                    success : function(data) {
                        let srr = '' , area = '';
                        data.forEach(function (val){

                            if( $("#province1").val() == val.name ){
                                val.city.forEach(function (v,k){
                                    if( k == 0 ){
                                        srr += `<option value="">请选择</option>`
                                    }
                                    srr += `<option value="${v.name}">${v.name}</option>`
                                })
                            }
                        })
                        $("#city").html(srr);
                        $("#city").val($("#city1").val())
                    }
                });
            }
        })
    }

}

$("#province").change(function (){
    let Thatval = $(this).val();
    cityList(Thatval);
})

$("#positionInfo").val($("#posInfo").val());
$("#titleInfo").val($("#tleInfo").val());
$("#politicalStatus").val($("#polStatus").val());

function cityList(Thatval){
    $.ajax({
        cache : true,
        type : "get",
        url:'/js/city.json',
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            let srr = '';
            data.forEach(function (val,k){
                if( Thatval == val.name ){
                    val.city.forEach(function (v,k){
                        if( k == 0 ){
                            srr += `<option value="">请选择</option>`
                        }
                        srr += `<option value="${v.name}">${v.name}</option>`;
                    })
                }
            })
            $("#city").html(srr);
        }
    });
}

$("#city").change(function (){
    let Thatval = $(this).val();
    $.ajax({
        cache : true,
        type : "get",
        url:'/js/city.json',
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            let srr = '';
            data.forEach(function (val){
                val.city.forEach(function (v){
                    if( Thatval == v.name ) {
                       v.area.forEach(function (item){
                           srr += `<option value="${item}">${item}</option>`
                        })
                    }
                })
            })
            $("#area").html(srr);
        }
    });
})

//上传营业执照
layui.use('upload', function () {
    var upload = layui.upload;
    upload.render({
        elem: '#business',
        url: '/common/sysFile/upload',
        accept: 'images', //只允许上传图片
        acceptMime: 'image/*', //只筛选图片
        size:10240,
        multiple:true,
        number:5,
        done: function (r) {

            let str = `
                    <div class="closeBtn">
                        <img class="upImg" src="${r.data}" width="100" height="100"/>
                        <span class="iconclose"><img src="../../../../img/close.png"></span>
                    </div>
                `
            $("#license1").html(str).show();
            $("#license").val(r.data);
            $(".iconclose").click(function (){
                $(this).parent('.closeBtn').remove();
                $("#license1").html('')
                $("#license").val('')
            })
        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});

layui.use('upload', function () {
    var upload = layui.upload;
    upload.render({
        elem: '#btnAdd',
        url: '/common/sysFile/upload',
        accept: 'images', //只允许上传图片
        acceptMime: 'image/*', //只筛选图片
        size:10240,
        multiple:true,
        number:5,
        done: function (r) {

            let str = [], srr = $("#brandImgas").val() , asr = '';
            str = srr.split(',');
            str.push(r.data);

            str.forEach(function (item,index){
                if(item != ''){
                    asr += `<div class="closeBtn"><img class="upImg" src="${item}" /><span class="iconclose"><img src="../../../img/close.png"></span></div>`
                }
            })

            $("#brandImgs").html(asr)

            $(".iconclose").click(function (){
                $(this).parent('.closeBtn').remove();
                returnImg('#brandImgs','#brandImgas');
            })

            returnImg('#brandImgs','#brandImgas')

        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});

layui.use('upload', function () {
    var upload = layui.upload;
    upload.render({
        elem: '#btnAddes',
        url: '/common/sysFile/upload',
        accept: 'images', //只允许上传图片
        acceptMime: 'image/*', //只筛选图片
        size:10240,
        multiple:true,
        number:5,
        done: function (r) {

            let str = [], srr = $("#certificateUrl").val() , asr = '';
            str = srr.split(',');
            str.push(r.data);

            str.forEach(function (item,index){
                if(item != ''){
                    asr += `<div class="closeBtn"><img class="upImg" src="${item}" /><span class="iconclose"><img src="../../../img/close.png"></span></div>`
                }
            })

            $("#brandlogo").html(asr)

            $(".iconclose").click(function (){
                $(this).parent('.closeBtn').remove();
                returnImg('#brandlogo','#certificateUrl');
            })

            returnImg('#brandlogo','#certificateUrl')

        },
        error: function (r) {
            layer.msg(r.msg);
        }
    });
});

function returnImg(a,b){
    let str = [] , srr;

    $(a).find('.closeBtn').each(function (k,v){
        str.push($(v).find('.upImg').attr('src'))
    })

    srr = str.join();
    $(b).val(srr)
}


function save() {

    if( !$("#province").val() ){
        layer.msg('省为必填项');
        return false;
    }

    if( !$("#city").val() ){
        layer.msg('市为必填项');
        return false;
    }


    $.ajax({
        cache : true,
        type : "POST",
        url : "/jzweb/examRegistration/saveExamUserRegistration",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}

function editSave() {

    $.ajax({
        cache : true,
        type : "POST",
        url : "/jzweb/examRegistration/updateExamUserRegistration",
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}